import os
import conf
from google.appengine.ext.webapp import template
from google.appengine.api import users

def search_bar(s):
  params = {
    "search_query": s.request.get("q", default_value=""),
  };
  path = os.path.join(os.path.dirname(__file__), 'search-bar.html')
  return template.render(path, params)

def user_bar(s):
  if users.get_current_user():
    url = users.create_logout_url(s.request.uri)
    url_linktext = 'Logout'
  else:
    url = users.create_login_url(s.request.uri)
    url_linktext = 'Login'

  params  = {
    'usernickname': users.get_current_user(),
    'is_user_admin': users.is_current_user_admin(),
    'url_linktext': url_linktext,
    'url': url,
  }
  path = os.path.join(os.path.dirname(__file__), 'user-bar.html')
  return template.render(path, params)
